package pms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import pms.dao.SaisonDao;


/** 
 * <p>
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * </p>
 * 
 * <p>
 * ModelAndView contains
 * <ul>
 * <li>title: Will be used as a headline in the resulting view</li>
 * <li>message: Some hints for the user</li>
 * <li>saison: A list/set of saison</li>
 * <li>command: A command that will be used in the links of the list of Saison (on the view)</li>
 * </ul>
 * The name of the selected view will be: 'list-saison.jsp'.
 * </p>
 * 
 * @see SaisonDao
 * @author josef@dr-schneeberger.de
 */
public class AlleSaisonen extends AbstractController {
    private static Log log = LogFactory.getLog(AlleSaisonen.class);
	private SaisonDao saisonDao;

	public void setSaisonDao(SaisonDao saisonDao) {
		this.saisonDao = saisonDao;
	}
	
	public SaisonDao getSaisonDao() {
		return saisonDao;
	}

	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		log.info(httpServletRequest.getPathTranslated());
		ModelAndView mv = new ModelAndView();
		mv.addObject("title", "Liste der Saisonen");
		mv.addObject("message", "Sie sehen hier eine Auflistung aller Saisonen im Verein");
		mv.addObject("saison", saisonDao.findAll()); //thesaison
		mv.addObject("edit", true);
		mv.setViewName("list-saison");
		return mv;
	}

}
